<template>
  <div>
    <el-form-item label="模式">
      <el-radio-group v-model="formValue.type">
        <el-radio-button label>Outset</el-radio-button>
        <el-radio-button label="inset">Inset</el-radio-button>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="颜色">
      <InputColor v-model="formValue.color" />
    </el-form-item>
    <el-form-item label="x轴偏移量">
      <InputNumber v-model="formValue.x" />
    </el-form-item>
    <el-form-item label="y轴偏移量">
      <InputNumber v-model="formValue.y" />
    </el-form-item>
    <el-form-item label="模糊半径">
      <InputNumber v-model="formValue.fuzzy" />
    </el-form-item>
    <el-form-item label="扩散半径">
      <InputNumber v-model="formValue.spread" />
    </el-form-item>
  </div>
</template>

<script>
import InputNumber from "../huComponents/InputNumber.vue";
import InputColor from "../huComponents/InputColor.vue";

export default {
  name: "ShadowConfig",
  components: { InputNumber, InputColor },
  props: {
    value: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      formValue: { x: "", y: "", fuzzy: "", spread: "", color: "", type: "" },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      const boxShadow = this.value.split(" ");
      this.formValue = {
        x: boxShadow[0] || "",
        y: boxShadow[1] || "",
        fuzzy: boxShadow[2] || "",
        spread: boxShadow[3] || "",
        color: boxShadow[4] || "",
        type: boxShadow[5] || "",
      };
    },
  },
  watch: {
    value: {
      immediate: true,
      deep: true,
      handler(newValue) {
        if (newValue) this.init();
      },
    },
    formValue: {
      immediate: true,
      deep: true,
      handler() {
        const boxShadow =
          this.formValue.x +
          " " +
          this.formValue.y +
          " " +
          this.formValue.fuzzy +
          " " +
          this.formValue.spread +
          " " +
          this.formValue.color +
          " " +
          this.formValue.type;
        if (boxShadow !== this.value) {
          this.$emit("input", boxShadow);
        }
      },
    },
  },
};
</script>

<style lang="scss" scoped>
</style>